/*
 * @author Robert Hanwell
 * @version 3
 * @since January
 */
package com.smartbox.floodaction;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;

// TODO: Auto-generated Javadoc
/**
 * The Class MainMenu.
 */
public class MainMenu extends Activity implements OnItemClickListener {

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainmenu);
		GridView gridview = (GridView) findViewById(R.id.gvMenu);
		gridview.setAdapter(new ImageAdapter(this));
		gridview.setOnItemClickListener(this);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget
	 * .AdapterView, android.view.View, int, long)
	 */
	@Override
	public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

		Intent myIntent = null;
		switch (position) {
		case 0:
			myIntent = new Intent(
					"com.smartbox.floodaction.CREATEEDITVOLUNTEER");
			break;
		case 1:
			myIntent = new Intent("com.smartbox.floodaction.GROUPACTIONPLAN");
			break;
		case 2:
			myIntent = new Intent("com.smartbox.floodaction.CAPTABBAR");
		}

		startActivity(myIntent);
	}

	/**
	 * The Class ImageAdapter.
	 */
	public class ImageAdapter extends BaseAdapter implements ListAdapter {

		/** The m context. */
		private Context mContext;

		/**
		 * Instantiates a new image adapter.
		 * 
		 * @param c
		 *            the c
		 */
		public ImageAdapter(Context c) {
			mContext = c;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see android.widget.Adapter#getCount()
		 */
		@Override
		public int getCount() {
			return mThumbIds.length;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see android.widget.Adapter#getItem(int)
		 */
		@Override
		public Object getItem(int position) {
			return null;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see android.widget.Adapter#getItemId(int)
		 */
		@Override
		public long getItemId(int position) {
			return 0;
		}

		// create a new ImageView for each item referenced by the Adapter
		/*
		 * (non-Javadoc)
		 * 
		 * @see android.widget.Adapter#getView(int, android.view.View,
		 * android.view.ViewGroup)
		 */
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView imageView;
			if (convertView == null) {
				imageView = new ImageView(mContext);
				imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
				imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
				imageView.setPadding(8, 8, 8, 8);
			} else {
				imageView = (ImageView) convertView;
			}
			imageView.setImageResource(R.drawable.ic_launcher);
			return imageView;
		}

		/** The m thumb ids. */
		private Integer[] mThumbIds = { R.drawable.ic_launcher,
				R.drawable.ic_launcher, R.drawable.ic_launcher };
	}

}
